package de.jmda.mview.fx.node.typeshape.relation;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.geometry.Point2D;
import de.jmda.fx.node.ArrowOrthogonal.Orientation;
import de.jmda.fx.node.ArrowOrthogonal;
import de.jmda.mview.fx.node.typeshape.Typeshape;
import de.jmda.util.gui.awt.graphics.RelationEndpoint.Style;

public class RelationEndpointTargetHas
		extends RelationEndpointTarget
{
//	private final static Logger LOGGER =
//      Logger.getLogger(RelationEndpointTargetHas.class);

	public RelationEndpointTargetHas(Typeshape typeshape)
	{
		super(typeshape);
		
		// initially add anchor to bottom of typeshape
		typeshape.addBottom(anchorToTypeshape);
		
		// initially locate arrow at the bottom side of fieldview with up direction
		arrow =
				new ArrowOrthogonal(
						new Point2D(
								typeshape.getBoundsInParent().getMinX() +
										((typeshape.getBoundsInParent().getMaxX() -
										  typeshape.getBoundsInParent().getMinX()) / 2),
								typeshape.getBoundsInParent().getMaxY()),
						(double) 10,
						Style.OPEN,
						false,
						(double) 4,
						Orientation.UP);

		anchorToTypeshape.pointProperty().addListener
		(
				new ChangeListener<Point2D>()
				{
					@Override
					public void changed(ObservableValue< ? extends Point2D> source,
					    Point2D oldValue, Point2D newValue)
					{
						arrow.setLayoutX(newValue.getX());
						arrow.setLayoutY(newValue.getY());

//						LOGGER.debug(arrow.coordinatesAsString());
					}
				}
		);
	}
}